package DT42;

import javagprssrv.JGS_Param;
import javagprssrv.Common.CommonClass;

public class DT42_DataStruct
{
    java.lang.String RemoteIP;
    int RemotePort;
    java.lang.String strAllData;
    java.lang.String strLength;
    java.lang.String strC;
    java.lang.String strA;
    java.lang.String strA_A1;
    java.lang.String strA_A2;
    java.lang.String strA_A3;
    java.lang.String strData;
    java.lang.String strAFN;
    int intAFN;
    java.lang.String strSEQ;
    java.lang.String strSEQ_TpV;
    java.lang.String strSEQ_FIR;
    java.lang.String strSEQ_FIN;
    java.lang.String strSEQ_CON;
    java.lang.String strSEQ_PSEQ_RSEQ;
    java.lang.String strCS;
    int intPn;
    int intFn;
    
    public DT42_DataStruct() {
        this.RemoteIP = "";
        this.RemotePort = -1;
        this.strAllData = "";
        this.strLength = "";
        this.strC = "";
        this.strA = "";
        this.strA_A1 = "";
        this.strA_A2 = "";
        this.strA_A3 = "";
        this.strData = "";
        this.strAFN = "";
        this.intAFN = -1;
        this.strSEQ = "";
        this.strSEQ_TpV = "";
        this.strSEQ_FIR = "";
        this.strSEQ_FIN = "";
        this.strSEQ_CON = "";
        this.strSEQ_PSEQ_RSEQ = "";
        this.strCS = "";
    }
    
    public void ReadDT42Data(final java.lang.String Data) {
        this.strAllData = Data;
        this.ReadDT42Data();
    }
    
    public void ReadDT42Data(final java.lang.String Data, final java.lang.String _RemoteIP, final int _RemotePort) {
        this.strAllData = Data;
        this.RemoteIP = _RemoteIP;
        this.RemotePort = _RemotePort;
        this.ReadDT42Data();
    }
    
    private java.lang.Boolean isBitEquals1(final java.lang.String strByte, final int index) {
        java.lang.Boolean res = java.lang.Boolean.FALSE;
        if (index > 7) {
            return res;
        }
        if (index < 0) {
            return res;
        }
        if (strByte.length() <= 0) {
            return res;
        }
        int by = strByte.charAt(0);
        by = (by << 7 - index) % 255;
        if (by >= 128) {
            res = true;
        }
        return res;
    }
    
    public void UpdateDT42Term(final java.lang.String _A_A1, final java.lang.String _A_A2, final java.lang.String _A_A3, final java.lang.String _RemoteIP, final int _RemotePort) {
        final java.lang.String A_A1 = new javagprssrv.Common.CommonClass().String2Hex(_A_A1, "");
        final int lenA_A2 = _A_A2.length();
        int A_A2 = 0;
        for (int i = 0; i < lenA_A2; ++i) {
            final int c = _A_A2.charAt(i);
            A_A2 += new Double((c * java.lang.Math.pow(256.0, i))).intValue();
        }
        int A_A3 = 0;
        A_A3 = _A_A3.charAt(0);
    }
    
    public void ReadDT42Data() {
        try {
            this.strLength = this.strAllData.substring(1, 3);
            this.strC = this.strAllData.substring(6, 7);
            this.strA = this.strAllData.substring(7, 12);
            this.strA_A1 = this.strA.substring(0, 2);
            this.strA_A2 = this.strA.substring(2, 4);
            this.strA_A3 = this.strA.substring(4, 5);
            this.strA = new javagprssrv.Common.CommonClass().String2Hex(this.strA, "");
            this.strData = this.strAllData.substring(12, this.strAllData.length() - 2 + 1);
            this.strAFN = this.strData.substring(0, 1);
            this.intAFN = this.strAFN.charAt(0);
            this.strSEQ = this.strData.substring(1, 2);
            if (this.isBitEquals1(this.strSEQ, 7)) {
                this.strSEQ_TpV = "1";
            }
            else {
                this.strSEQ_TpV = "0";
            }
            if (this.isBitEquals1(this.strSEQ, 6)) {
                this.strSEQ_FIR = "1";
            }
            else {
                this.strSEQ_FIR = "0";
            }
            if (this.isBitEquals1(this.strSEQ, 5)) {
                this.strSEQ_FIN = "1";
            }
            else {
                this.strSEQ_FIN = "0";
            }
            if (this.isBitEquals1(this.strSEQ, 4)) {
                this.strSEQ_CON = "1";
            }
            else {
                this.strSEQ_CON = "0";
            }
            final java.lang.String strPn = this.strAllData.substring(14, 16);
            final int keyPn_0 = strPn.charAt(0);
            final int keyPn_2 = strPn.charAt(1);
            int _Pn_0 = 0;
            for (int i = 0; i < 8; ++i) {
                if (java.lang.Math.pow(2.0, i) == keyPn_0) {
                    _Pn_0 = i + 1;
                    break;
                }
            }
            int _Pn_2 = 0;
            for (int j = 0; j < 8; ++j) {
                if (java.lang.Math.pow(2.0, j) == keyPn_2) {
                    _Pn_2 = j;
                    break;
                }
            }
            final int _Pn = _Pn_0 + _Pn_2 * 8;
            final java.lang.String strFn = this.strAllData.substring(16, 18);
            final int keyFn_0 = strFn.charAt(0);
            final int keyFn_2 = strFn.charAt(1);
            int _Fn = 0;
            for (int k = 0; k < 8; ++k) {
                if (java.lang.Math.pow(2.0, k) == keyFn_0) {
                    _Fn = k + 1;
                    break;
                }
            }
            _Fn += keyFn_2 * 8;
            this.intPn = _Pn;
            this.intFn = _Fn;
            javagprssrv.JGS_Param.myLog.ShowLog("AFN = " + new javagprssrv.Common.CommonClass().String2Hex(this.strAFN, " "), java.lang.Boolean.TRUE, java.lang.Boolean.FALSE);
            javagprssrv.JGS_Param.myLog.ShowLog("SEQ = " + new javagprssrv.Common.CommonClass().String2Hex(this.strSEQ, " "), java.lang.Boolean.TRUE, java.lang.Boolean.FALSE);
            javagprssrv.JGS_Param.myLog.ShowLog("( SEQ_TpV = " + this.strSEQ_TpV + "," + "SEQ_FIR = " + this.strSEQ_FIR + "," + "SEQ_FIN = " + this.strSEQ_FIN + "," + "SEQ_CON = " + this.strSEQ_CON + " )", java.lang.Boolean.TRUE, java.lang.Boolean.FALSE);
            javagprssrv.JGS_Param.myLog.ShowLog("( Pn = " + this.intPn + "," + "Fn = " + this.intFn + " )", java.lang.Boolean.TRUE, java.lang.Boolean.FALSE);
        }
        catch (java.lang.Exception ex) {}
    }
}
